<?php
class Model_Colibri_Setting extends Model
{
    private $_settings = array();

    public function __construct()
    {
        $settings = DB::select()->from('settings')->execute()->as_array();
        foreach($settings as $line)
        {
            $this->_settings[$line['name']] = $line['value'];
        }


    }

    public function get($key = NULL)
    {
        if($key == NULL)
        {
            return $this->_settings;
        }
        elseif(isset($this->_settings[$key]))
        {
            return $this->_settings[$key];
        }
        else
        {
            return FALSE;
        }
    }

    public function set($key, $value = "")
    {
        if (array_key_exists($key,$this->_settings))
        {
            DB::update('settings')->set(array('value'=>$value))->where('name','=',$key)->execute();
        }
        else
        {
            DB::insert('settings',array('name','value'))->values(array($key,$value))->execute();
        }
        $this->_settings[$key] = $value;
    }
}